﻿using System;


namespace Common
{
    public class Tokenizer
    {
        long m_nLen;
        long m_nCursor;
        char[] m_buff = null;

        public Tokenizer()
        {
            //
            // TODO: 여기에 생성자 논리를 추가합니다.
            //
        }
        public Tokenizer(string sData)
        {
            m_nLen = sData.Length;
            m_buff = sData.ToCharArray();
            m_nCursor = 0;
        }
        private string Substring(long start, long count)
        {
            long cnt = 0;
            char[] temp = new char[count];
            for (long i = start; i < start + count; i++, cnt++)
            {
                temp[cnt] = m_buff[i];
            }
            return new string(temp);
        }
        public string StrTok(char sep)
        {
            for (long i = m_nCursor; i < m_nLen; i++)
            {
                if (m_buff[i] == sep)
                {
                    long len = i - m_nCursor;
                    string sVal = Substring(m_nCursor, i - m_nCursor);
                    m_nCursor = i + 1;
                    return sVal;
                }

                if (i == m_nLen - 1)
                {
                    long len = m_nLen - m_nCursor;
                    string sVal = Substring(m_nCursor, m_nLen - m_nCursor);
                    m_nCursor = i + 1;
                    return sVal;
                }
            }
            return "";
        }
    }
}
